/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LOTTIETURBO_ANIMATOR_H
#define LOTTIETURBO_ANIMATOR_H
#include <arkui/native_animate.h>
#include <cstdint>
#include <string>

namespace LottieTurbo {
class Animator {
public:
    enum class AnimatorStatus {
        IDLE,
        INIT,
        PLAY,
        STOP,
        END,
        PAUSE
    };
    ~Animator();
    int32_t SetDuration(int32_t duration);
    int32_t SetDelay(int32_t delay);
    int32_t SetIterations(int32_t);
    int32_t SetBegin(float begin);
    int32_t SetEnd(float end);
    int32_t SetEasing(ArkUI_AnimationCurve easing);
    int32_t SetDirection(ArkUI_AnimationDirection direction);
    int32_t SetFill(ArkUI_AnimationFillMode fill);

    /**
     * @brief 保存frameRateRange
     * @param frameRateRange 帧率范围
     */
    void SetFrameRateRange(ArkUI_ExpectedFrameRateRange frameRateRange);

    /**
     * @brief 获取frameRateRange
     */
    ArkUI_ExpectedFrameRateRange GetSetFrameRateRange() const;

    /**
     * @brief 设置frameRateRange给ArkUI
     * @return Returns the error code.
     *         Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful.
     *         Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs.
     */
    int32_t UpdateFrameRateRange();

    void Init(ArkUI_ContextHandle context);
    std::function<void()> FunctionCallBack;
    int32_t Play();
    int32_t Pause();
    int32_t Stop();
    const AnimatorStatus GetStatus() const;

private:
    int32_t duration_{0};
    ArkUI_AnimationCurve easing_{ARKUI_CURVE_LINEAR};
    int32_t delay_{0};
    ArkUI_AnimationDirection direction_{ARKUI_ANIMATION_DIRECTION_NORMAL};
    int32_t iterations_{-1};
    float begin_{0};
    float end_{1};
    ArkUI_ExpectedFrameRateRange frameRateRange_{.min = 0, .max = 0, .expected = 0};
    ArkUI_AnimationFillMode fill_{ARKUI_ANIMATION_FILL_MODE_FORWARDS};
    ArkUI_AnimatorOption *animatorOption_{nullptr};
    ArkUI_AnimatorHandle animatorHandle_{nullptr};
    ArkUI_NativeAnimateAPI_1 *animateAPi_1_{nullptr};
    static void OnCallBack(ArkUI_AnimatorOnFrameEvent *event);
    std::atomic<AnimatorStatus> status_{Animator::AnimatorStatus::IDLE};
};
} // namespace LottieTurbo
#endif // LOTTIETURBO_ANIMATOR_H
